/********************************************************************
	created:	2012/04/08   17:49
	filename: 	hy_handler_alloc_hook.h
	author:		supercaco@sina.com
	purpose:	
*********************************************************************/
#ifndef _HY_HANDLER_ALLOC_HOOK_H_
#define _HY_HANDLER_ALLOC_HOOK_H_


namespace hy {

	/// Default allocation function for handlers.
	/**
	* Asynchronous operations may need to allocate temporary objects. Since
	* asynchronous operations have a handler function object, these temporary
	* objects can be said to be associated with the handler.
	*
	* Implement zr_handler_allocate and zr_handler_deallocate for your own
	* handlers to provide custom allocation for these temporary objects.
	*
	* This default implementation is simply:
	* @code
	* return ::operator new(size);
	* @endcode
	*
	* @note All temporary objects associated with a handler will be deallocated
	* before the upcall to the handler is performed. This allows the same memory to
	* be reused for a subsequent asynchronous operation initiated by the handler.
	*
	* @par Example
	* @code
	* class my_handler;
	*
	* void* zr_handler_allocate(std::size_t size, my_handler* context)
	* {
	*   return ::operator new(size);
	* }
	*
	* void zr_handler_deallocate(void* pointer, std::size_t size,
	*     my_handler* context)
	* {
	*   ::operator delete(pointer);
	* }
	* @endcode
	*/
	inline void* hy_handler_allocate(std::size_t size, ...)
	{
		return ::operator new(size);
	}

	/// Default deallocation function for handlers.
	/**
	* Implement zr_handler_allocate and zr_handler_deallocate for your own
	* handlers to provide custom allocation for the associated temporary objects.
	*
	* This default implementation is simply:
	* @code
	* ::operator delete(pointer);
	* @endcode
	*
	* @sa zr_handler_allocate.
	*/
	inline void hy_handler_deallocate(void* pointer, std::size_t size, ...)
	{
		(void)(size);
		::operator delete(pointer);
	}

} // namespace hy

#endif //_HY_HANDLER_ALLOC_HOOK_H_

